package org.vaadinetherealintegration.client.example2;

import etrl.core.LightStore;
import etrl.core.NodeCallback;
import etrl.vecmath.Vector3f;
import etrl.vecmath.Vector4f;

public class LightCallback implements NodeCallback
{
	private float _alpha;
	private final float ALPHA_STEP = 3.f;
	
	public LightCallback()
	{
		_alpha = 0.f;
	}
	
	public void doIt()
	{
		Vector4f lightData = LightStore.getInstance().getLightSourceData("MobileLight");
		
		// get distance from (0., 0., 0.)
		Vector3f position = new Vector3f(lightData.x, lightData.y, lightData.z);
		float dist = position.length();
		
		// Compute new position
		float x = (float) (Math.cos(_alpha * Math.PI / 180.f) * dist); 
		float z = (float) (Math.sin(_alpha * Math.PI / 180.f) * dist);
		
		LightStore.getInstance().setLightPositionDirection("MobileLight", new Vector3f(x, lightData.y, z));
		
		_alpha += ALPHA_STEP;
	}

}
